<?php
namespace app\model;
use app\controller\UserInfo;
use think\model;

class UserInfos extends Model{

    protected $table = "user_info";

    // 完善个人信息
    public function saveUserInfo($data){
        try {
            $id = $data["id"];
            foreach ($data as $k=>$v){
                // 爱好数组
                if($k=="hobby"){
                    continue;
                };
                // 其余基本信息存入 user_info表中
                UserInfos::update(
                    [
                        $k=>$v
                    ],
                    // 更新条件
                    [
                        "id"=>$id
                    ]
                );
            }
            return 1;
        }catch (Exception $e){

            return -1;
        }
    }


    // 默认添加的用户信息 id uid uname
    public function insertUserInfo($id,$uname,$uid){
        $user = UserInfos::create([
            'id'=>$id,
            'uname'=>$uname,
            'uid'=>$uid,
        ]);
    }


    // 查询当前用户的用户信息
    public function queryUserInfo($id){
        $user = UserInfos::where("id",$id)->find();
        return $user;
    }

}